package com.platform.user.controller;

import com.platform.common.annotation.ApiResponseBody;
import com.platform.common.enums.RoleEnum;
import com.platform.common.result.ApiException;
import com.platform.common.result.ApiExceptionEnum;
import com.platform.user.model.UserDO;
import com.platform.user.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author shuc
 */
@ApiResponseBody
@Controller
@RequestMapping("/user")
public class AuditController {
    @Resource
    private UserService userService;

    @PostMapping("/ban")
    public Boolean ban(@RequestBody Map<String, String> requestMap) {
        String id = requestMap.get("id");
        UserDO userDO = UserDO.builder()
                .id(id)
                .role(RoleEnum.BANNED.getName())
                .build();
        Boolean result = userService.updateById(userDO);
        if (!result) {
            throw new ApiException(ApiExceptionEnum.DB_FAIL);
        }
        return true;
    }
}
